home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************************
- *
- *
- * Evaluate.h - header file for Evaluate.Lib
- *
- * ©1994, Graham Cox. All Rights Reserved.
- *
- * May 16th, 1994
- *
- *
- ****************************************************************************************/
-
- /*
-
- This library is fairly complex and contains many functions. However, you only need one of
- them to use it- Evaluate. This function takes a pascal string and a value, and returns
- the result of the expression in the string. It also returns an error code which is one
- of the error values listed below, or noErr. The parser looks up tokens in a resource of
- type 'TOKN', which is hard coded in the library to have the ID 128, The following
- constants are provided for your convenience, but changing them will NOT result in the
- library using a different reource type or ID. If you wish to look up a string corresponding
- to the error code, subtract 100 from the code and use it as an index into the STR#
- resource which is also provided with the ID given below. This ID may be changed to fit
- your app's resource ID numbering because this is not used by this library.
-
- */
-
-
-
-
- #define tokenTableResType 'TOKN'
- #define tokenTableResID 128
-
- #define SyntaxError 100
- #define LRParenError 101
- #define IllegalTokErr 102
- #define ParseError 103
- #define endOfLine 104
- #define OutOfMemory 105
- #define ItsAllGoneWrong 106
- #define NoTokenTable 107
-
- #define ErrorStringListID 130
-
- /* globals */
-
- extern int CompileError; // global error flag
- extern int gCurrentMark; // current character being scanned
-
-
-
- /*
-
- Function Prototype
-
- */
-
- OSErr Evaluate(Str255 *inputStr,extended *value);
-
-
- /*
-
- To call this function, create a pascal string containing the expression to be evaluated.
- e.g. myExpression = "\p1.5*cos(x)+sin(x/2)" and pass its address in inputStr. Pass the
- value of x in value. All expressions should be in terms of x- other variables can be
- inserted but they will be automatically evaluated at a value of zero. There is no easy
- way to insert values for these variables, though the library supports this.
-
- How it works: The expression parsed from left to right and is converted to Reverse Polish
- aka Postfix notation. This notation is stored internally in a queue structure. The RPN
- queue is then evaluated using an evaluation stack. Errors can be encountered in either
- stage which aborts the process and returns the error code. The internal structures are
- created and destroyed completely internally- there is no action you need to take to
- manage this. Be aware however, that these internal structures can grow large if an
- expression is very complex, so be sure to give your app enough memory.
-
- The prototypes of other internal routines are listed here for completeness. You should not
- need to call them- if you do you are on your own. They are listed here because they are
- not private, and so if you get a linker conflict with your own functions, this may allow
- you to identify the culprit!
-
-
- QSHandle MakeRPNQueue(Str255* inString);
- extended** MakeFPObject(extended fpData);
- varEntryHdl MakeVarObject(extended fpData,char* vName);
- varTabHdl MakeVariableTable(QSHandle rpnQueue);
- QSHandle CloneQSStruct(QSHandle src);
- extended EvaluateRPN(QSHandle rpnQueue,varTabHdl vTab);
-
- QSHandle NewQSStruct(int sqType);
- void DisposeQSStruct(QSHandle theQS);
- QSElemHdl NewQSItem(int qsType,long qsData);
- void DisposeQSItem(QSElemHdl theItem);
- void PushQSItem(QSElemHdl theItem,QSHandle theQS);
- QSElemHdl PopQSItem(QSHandle theQS);
- QSElemHdl PeekQSItem(QSHandle theQS);
- Boolean EmptyQSStruct(QSHandle theQS);
- long QSLength(QSHandle theQS);
-
- tkTabHdl GetTokenTable(int resourceID);
- Boolean IsBinOp(char theChar);
- Boolean IsBracket(char theChar);
- Boolean LegalPair(char firstChar,char secondChar);
- int GetNextRawToken(char* inString,char* outString,int *sectLength);
- void RemoveWhiteSpace(char* theString);
- int GetToken(tkTabHdl ttTable,char* rawString,tEntry* theToken);
- void RPNConversion(QSElemHdl qItem,QSHandle stack,QSHandle queue);
- void ReadRPNString(QSHandle rpnQueue,Str255* theString);
-
-
- This library uses the THINK C implementation of SANE- you should include <Sane.h> in your
- project and the SANE library. It deals with all floating point values as extended types,
- and you should compile your project with 'Native Floating Point Format' ON. It also relies
- on MacTraps.
-
- The header files of the components which make up this library are also supplied- in general
- there is no need to include them- just this one will do.
-
- */
-
-
-
-